import SocketServer
import os       

class UmbiRequestHandler(SocketServer.BaseRequestHandler ):
    
    dict = {}
    
    def setup(self):
        print self.client_address, 'connected! "bye" to close'
        execfile("__forth@python.py", self.dict)

    def handle(self):
        while 1:
            data = self.request.recv(1024 * 64)
            print "Data>",data, "<"
            if data.strip() == 'bye':
            	 return
            data = data.replace("\r\n","\n")
            exec(data, self.dict)

    def finish(self):
        print self.client_address, 'disconnected!'

class MyServer(SocketServer.ThreadingTCPServer):
    allow_reuse_address = 1
    
server = MyServer(('', 3456),UmbiRequestHandler)

if __name__ == "__main__":
    print "Umbiserving" 
    server.serve_forever()
